//
//  GestureTableViewCell.swift
//  EasePods
//
//  Created by 易先生 on 2024/4/30.
//

import UIKit

class GestureTableViewCell: TableViewCell {
    
    override func makeUI() {
        super.makeUI()
        
        self.addSubview(cardView)
        cardView.addSubview(titleLabel)
        cardView.addSubview(selectImageView)
        
        cardView.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.leading.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
        }
        
        titleLabel.snp.makeConstraints { make in
            make.leading.equalToSuperview()
            make.top.equalToSuperview().offset(10)
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-10)
        }
        
        selectImageView.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-40)
            make.centerY.equalToSuperview()
        }
    }
    
    public func bind(to viewModel: GestureCellViewModel) {
        
        titleLabel.text = viewModel.buttonFuncType.title
        viewModel.isSelect.subscribe(onNext: { [weak self] isSelect in
            guard let `self` = self else { return }
            if isSelect {
                titleLabel.font = Fonts.mediumSystemFont(ofSize: 14)
                selectImageView.isHidden = false
                cardView.backgroundColor = R.color.common_16_bg()
            } else {
                selectImageView.isHidden = true
                cardView.backgroundColor = .clear
                titleLabel.font = Fonts.systemFont(ofSize: 14)
            }
        }).disposed(by: cellDisposeBag)
    }
    
    private lazy var cardView: View = {
        let view = View()
        view.backgroundColor = .clear
        return view
    }()
    
    private lazy var titleLabel: Label = {
        let label = Label()
        label.font = Fonts.systemFont(ofSize: 14)
        label.textColor = R.color.common_3_text()
        label.textAlignment = .center
        return label
    }()
    
    private lazy var selectImageView: ImageView = {
        let imageView = ImageView()
        imageView.image = R.image.ic_common_pick()
        imageView.isHidden = true
        return imageView
    }()

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

